/**
 * 
 */
package pl.net.beercrm.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Date;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * @author Rafi
 * 
 */
public class PropertiesUtil {
	
	private final static Log log = LogFactory.getLog(PropertiesUtil.class);

	private final static String configPath = "/config.properties";

	private static Properties properties = new Properties();

	public static Properties getProperties() throws IOException {
		properties.load(PropertiesUtil.class.getResourceAsStream(configPath));
		return properties;
	}

	public static void setProperties(Properties updatedProperties) {
		properties = updatedProperties;
	}

	public static void storeProperties() throws IOException, URISyntaxException {
		URL url = PropertiesUtil.class.getResource(configPath);
		log.debug("URL: " + url.toURI().toString());
		properties.store(new FileOutputStream(new File(url.toURI())),
				"Properties updated at " + new Date().toString());
	}
}
